﻿using Smokey.Shared.DataTransferObjects;
using System.Windows.Controls;

namespace Smokey.Client.Screens.Applications {

    internal partial class ApplicationSearch : UserControl {

        public ApplicationSearch() {
            InitializeComponent();
        }

        public ApplicationSearchViewModel ViewModel {
            get {
                return (ApplicationSearchViewModel)this.DataContext;
            }
        }

        private void AddApplication_Click(object sender, System.Windows.RoutedEventArgs e) {
            ViewModel.Context.ShowViewApplicationScreen(null);
        }

        private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e) {
            ViewModel.LoadApplications();
        }

        private void ApplicationLink_Click(object sender, System.Windows.RoutedEventArgs e) {
            var application = this.ApplicationsGrid.SelectedItem as ApplicationDto;

            if (application != null) {
                ViewModel.Context.ShowViewApplicationScreen(application.ApplicationId);
            }
        }
    }
}
